Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new codemirror-promql-based expression editor #8634

Merged
merged 9 commits into from
Mar 23, 2021

Conversation

juliusv
Copy link
Member

@juliusv juliusv commented Mar 23, 2021

This adds advanced autocompletion, syntax highlighting, and linting
for PromQL.

Signed-off-by: Julius Volz julius.volz@gmail.com

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@Nexucis

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

1:13:18 PM: error codemirror-promql@0.13.0: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "12.18.0"

Looking at setting a higher Node version on Netlify...

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

Note that on Netlify, the autocompletion of metric names currently does not work because I haven't hacked new magic into Netlify yet to bend API requests over to our Prometheus demo server (instead of going directly to Netlify).

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

CircleCI's Node version is too old too (12 vs 14), but updating it is more cumbersome than on Netlify :/

https://circleci.com/docs/2.0/circleci-images/#best-practices

Seems like we would have to add Node update commands to the build job defined in the CircleCI orb at https://github.com/prometheus/circleci/blob/bc4e25f52b9f8a7c8110992e2d8892e07a0a9024/src/jobs/build.yml.

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

I'm not sure yet though why the tests on CircleCI have passed, but the build step is failing on a too old node version.

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

I'm not sure yet though why the tests on CircleCI have passed, but the build step is failing on a too old node version.

@simonpasquier @roidelapluie could someone more familiar with the CircleCI build system help figure out why that is?

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@Nexucis Yes, same as I fixed on Netlify already. But why does it only happen for the build step on CircleCI, and not the test step (which also runs React tests)?

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

Comparing the "Spin up environment" steps on CircleCI,

test has:

Build-agent version 1.0.54207-5704a5fc (2021-03-16T17:42:41+0000)
System information:
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: xfs
 Cgroup Driver: cgroupfs
 Kernel Version: 4.15.0-1092-aws
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64

Starting container circleci/golang:1.16-node
[...]

...whereas build doesn't seem to be using the golang:1.16-node image and just has:

Build-agent version 1.0.54207-5704a5fc (2021-03-16T17:42:41+0000)
Creating a dedicated VM with default image

Assigned VM request id: 25746778
  provisioning: ..
VM 'default-e77ee336-6d91-4619-9465-8a11acbcad15' has been created
Initializing agent

@roidelapluie
Copy link
Member

A
W
E
S
O
M
E

I think we should not default to the new editor, but make it default next release. I also don't think we should "hide" the checkboxes,instead I would disable them. I would also put them closer to the new editor checkbox, specifying that it is experimental.
Maybe move those 3 checkboxes to the right of the screen?

Looking into the build failure now.

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@roidelapluie I'll get right on that if you are looking at the build stuff :)

Copy link
Member

@Nexucis Nexucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no big issue from my point of view. I just left few comments, let me know if they are relevant.

options: this.queryHistory.map(q => ({
label: q.length < 80 ? q : q.slice(0, 76).concat('...'),
detail: 'past query',
apply: q,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps for this case, you should have a more sofisticated apply method. It's only in case you would like to replace the whole current expression when you are autocompleting a query from the history.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm happy enough with how it currently works: it only inserts at position 1, but doesn't overwrite anything that is already there... maybe it makes sense to play with it and optimize it in the future, if someone has a better idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright :). Fine for me too, I was just suggesting since I wasn't sure about the expected behavior expected of the query history


const { state, pos } = context;
const tree = syntaxTree(state).resolve(pos, -1);
const start = computeStartCompletePosition(tree, pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not a really good idea to use this method. You are quite lucky it is exported after all and it is not really part of what the library would like to expose. It's more a side effect here.

Perhaps something like that could work too :

return Promise.resolve(this.complete.promQL(context)).then( res => {
       const { state, pos } = context;
       const tree = syntaxTree(state).resolve(pos, -1);
       const start = res != null ? res.from : tree.from

       if (start !== 0) {
         return res;
       }
      
       // then put the logic to add the historyItems here
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks good! Changed it to that.

label: q.length < 80 ? q : q.slice(0, 76).concat('...'),
detail: 'past query',
apply: q,
info: q,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add only q if it has been truncated ? And nothing otherwise

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

apply: q,
info: q,
})),
span: /^[a-zA-Z0-9_:]+$/,
Copy link
Member

@Nexucis Nexucis Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure it is really important here, but there are some cases where the span is not added. I think the case appears when you are trying to autocomplete a duration.

So maybe we don't really care about that in this particular case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure about that either. But if I remove the span here completely, then the completion dropdown disappears and reappears on each typed character (which is slow and ugly), because the search is starting completely from zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can do that then:

span: res !== nul ? res.span : /^[a-zA-Z0-9_:]+$/,

Like that you won't erase what is coming from the previous complete object

Copy link
Member

@Nexucis Nexucis Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or let's keep it like you did. And let's see if there are some weird cases ^^. I don't really think someone will be able to reach this case anyway. So should be good

Copy link
Member

@Nexucis Nexucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really talk for the react code itself, but at least for the usage of codemirror, it looks nice :)

Thanks for doing it !

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@roidelapluie grouped the new boxes, renamed "new editor" to "experimental editor", and defaulting to the old editor for now.

Take another look :)

@roidelapluie
Copy link
Member

Thanks! We should probably disable query history and autocomplete when new editor is on.

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

Thanks! We should probably disable query history and autocomplete when new editor is on.

@roidelapluie Hm, why? Both are applicable to the new editor as well. Without autocomplete, it would be pretty sad in fact :)

@roidelapluie
Copy link
Member

Thanks! We should probably disable query history and autocomplete when new editor is on.

@roidelapluie Hm, why? Both are applicable to the new editor as well. Without autocomplete, it would be pretty sad in fact :)

didn't notice they work on both.

@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@Nexucis Thanks, will add "Fixes: ..." lines! The last one has already been fixed by the way, there's already a metrics explorer now.

This adds advanced autocompletion, syntax highlighting, and linting
for PromQL.

Fixes #6160
Fixes #5421

Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julius Volz <julius.volz@gmail.com>
@juliusv
Copy link
Member Author

juliusv commented Mar 23, 2021

@roidelapluie Good to merge now?

Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@juliusv juliusv merged commit faacb61 into main Mar 23, 2021
@juliusv juliusv deleted the feature/codemirror-editor branch March 23, 2021 22:55
@juliusv juliusv mentioned this pull request Mar 24, 2021
@flyinprogrammer
Copy link

@juliusv this is seriously amazing work, it will make learning PromQL much easier now, excellent job!

@juliusv
Copy link
Member Author

juliusv commented Mar 26, 2021

@flyinprogrammer Thank you (also to @Nexucis, who built a lot of the CodeMirror PromQL integration code).

@Nexucis
Copy link
Member

Nexucis commented Mar 26, 2021

thanks @flyinprogrammer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants